﻿using System;
using System.Data;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BaseData;
using BaseData.UI;
using TaxBiz.SysConfig;
using TaxBiz.User;
using TaxEntity.User;

namespace Admin.User
{
    public partial class ModifySelf : BaseCommon.BasePage
    {
        protected string departName = string.Empty;
        protected string gangweiName = string.Empty;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!HasPower())
            {
                Jscript.AlertAndGoBack("您权限不足，不能操作");
                return;
            }
            string action = PageContext.GetRequest("action");
            if (!string.IsNullOrEmpty(action))
            {
                this.DoAction(action);
            }
            else
            {
                DataTable dtDepartment = new DepartmentBiz().GetList();
                departName = BaseData.Common.TableHelper.GetStringValueFromTable(dtDepartment, "id=" + UserLogin.DepartmentID, "name");
                DataTable dtGangwei = PowerInfoBiz.GetGangweiList();
                gangweiName = BaseData.Common.TableHelper.GetStringValueFromTable(dtGangwei, "usertype=" + UserLogin.UserType, "typename");
            }
        }

        protected bool DoAction(string action)
        {
            UserBiz ub = new UserBiz();
            UserEntity ue = new UserEntity();
            ue.UserId = UserID;
            //其它参数
            ue.SName = PageContext.GetRequest("txtRealName");
            ue.EMail = PageContext.GetRequest("txtEmail");

            bool isSucc = ub.Update(ue, UserLogin);
            if (!isSucc)
            {
                Jscript.Alert("修改失败");
                return false;
            }

            Jscript.AlertAndRedirect("修改成功", "ModifySelf.aspx");
            return true;
        }
    }
}